package user

import (
	"context"
	"time"

	"github.com/jinzhu/gorm"
	_ "github.com/go-sql-driver/mysql"
)

var Orm *gorm.DB

func init()  {
	//连接数据库
	var err error
	Orm, err = gorm.Open("mysql", "root:root@tcp(127.0.0.1:3306)/lwyweb?charset=utf8&parseTime=True&loc=Local")
	if err != nil {
		panic(err)
	}


	Orm.DB().SetConnMaxLifetime(time.Second)
}

type UserServer struct {

}


func (this *UserServer) GetUsers(ctx context.Context, search *SearchUser) (*GetUsersRes, error) {

	res:=new(GetUsersRes)
	Orm.Debug().Table("t_user").Find(&res.Users)
	return res,nil
}

func (this *UserServer) GetUser(ctx context.Context, userId *UserId) (*User, error) {
	user:=new(User)

	Orm.Table("t_user").First(user,userId.Id)

	return user,nil
}

func (this *UserServer) Add(context.Context, *User) (*AddUserRes, error) {
	var res *AddUserRes
	return res,nil
}

func (this *UserServer) Edit(context.Context, *User) (*Error, error) {
	var res *Error
	return res,nil
}

func (this *UserServer) Del(context.Context, *UserId) (*Error, error) {
	var res *Error
	return res,nil
}



